package com.concurrence;

/**
 * VolatileDemo..
 *
 * @author Lizhong
 * @date 2019/3/30
 */
public class VolatileDemo {
    int a = 0;
    int c= 0;
       boolean delflag = false;

    public void w() {
        this.a = 3;
        this.delflag = true;
        this.c=2;
    }

    public void r() {
        boolean delFlag = this.delflag;
        int i = this.a * this.a;
        System.out.println(delFlag);
        System.out.println(i);
        if (delFlag) {
            System.out.println(this.a * this.a+"over******");
            /**
             * Out1: 存在情况
             *
             * 没有volatile修饰
             * false
             * 9
             *
             * Out2：存在情况
             * 有volatile修饰
             * false
             * 9
             */
        }
    }

    public static void main(String[] args) throws InterruptedException {
        int i=0;
        VolatileDemo volatileDemo = new VolatileDemo();
        Thread thread = new Thread(volatileDemo::w);
        Thread thread1 = new Thread(volatileDemo::r);
        thread.start();
        thread1.start();

        // i++;}
        Thread.sleep(500);
    }
}
